Repository navigation
Conversation
With uv_compile_bytecode on, only the dependencies were compiled: compileall ran inside the dependency install, before the source was copied into the artifacts directory. Add PythonUvCompileSourceAction after CopySourceAction. It compiles what was copied from the source, so dependencies are not compiled twice, and it also covers builds that have no manifest. A missing uv or source directory skips it with a warning instead of failing the build. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
bnusunny
left a comment
There was a problem hiding this comment.
Thanks, this fills the gap #926 left. The new PythonUvCompileSourceAction runs after CopySourceAction, and only when bytecode is enabled. It compiles just the top-level entries that CopySourceAction actually copied: the same EXCLUDED_FILES filter, with .py files and directories only. Dependencies aren't compiled a second time. It reuses the same compileall --invalidation-mode unchecked-hash call through UvRunner.compile_bytecode, and it warns instead of failing when uv, the target Python or the source directory is missing.
What I verified locally:
tests/unit/workflows/python_uv: 190 passed, 53 subtests.- With the new
actions.append(...)inworkflow.pydisabled, 3 tests fail. black --checkandruff checkare clean.- I ran
CopySourceActionand the new action against a real source tree, with the target Python stubbed to the local 3.12 interpreter:- The source tree had
app.py, apkg/, a.git/with a.pyinside, adata.txt, a file with a syntax error, and a dependency already installed in the artifacts directory. compileallreceived onlyapp.py,bad.pyandpkg.app.pyandpkg/__init__.pygot.pycfiles with flags=1 (unchecked-hash)..gitand the pre-installed dependency weren't touched.- The syntax error logged a warning and everything else was still compiled.
- The source tree had
One small nit is inline.
…test The excluded entries only existed in the source directory, so the artifacts existence check dropped them and the filter was never exercised. Put them in the artifacts directory too. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
bnusunny
left a comment
There was a problem hiding this comment.
Thanks for pinning the filter. I re-checked on e666ced: 190 unit tests pass, and with the exclude filter replaced by if True the updated test now fails, as it should. Re-approving, since the push dismissed my earlier approval.
Issue #, if available: Fixes #977
Description of changes
With
uv_compile_bytecodeon,compileallran inside the dependency install, beforeCopySourceAction, so the function's own source shipped without bytecode.PythonUvCompileSourceActionafterCopySourceAction. It compiles only the top-level entries that came from the source directory, so dependencies are not compiled twice.CopySourceActionthere are updated.UvRunner.compile_bytecode(python_version, paths)is the shared entry point;_compile_bytecodenow takes several paths.Description of how you validated changes
sam buildwith SAM CLI 1.174.0 and this branch on arequests+pydanticfunction: every.pyhas an unchecked-hash.pyc(200 of 200), also with--cachedand with norequirements.txt. A source file with a syntax error logs a warning and the build passes..pyc.ruff checkandblack --checkpass. Not tested on Windows.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
🤖 Generated with Claude Code